<template>
	<view class="history-section">
		<view class="history-list" :class="Historylist.length-1==index?'sroll':''" v-for="(item,index) in Historylist" :key="index"
		 @click="navTo('/pages/product/product?id='+item.goodsid)">
			<image :src="item.thumb" mode=""></image>
			<view class="list-title">
				<view class="clamp2">{{item.title}}</view>
				<view>￥{{item.saleprice}}</view>
			</view>
		</view>
		<view v-if="Wbott" class="bott-di">
			— — 到底啦 — —
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Historylist: [{
					title: '',
					saleprice: '0.00',
					thumb: ''
				}],
				scroll: 0,
				Stop: 0,
				pages: 1,
				Wbott:false,
				height: uni.getSystemInfoSync().windowHeight
			}
		},
		onPageScroll(e) {
			var that = this;
			const query = uni.createSelectorQuery().in(this);
			query.select('.sroll').boundingClientRect(data => {
				that.Stop = data.top - 9 * data.height;
				if (that.Stop < 0 && that.scroll == 1) {
					that.pages += 1;
					that.scroll = 0;
					uni.showLoading({
						title: '请稍后'
					})
					that.$axios('history/display', "POST", 'shop', {
						page: that.pages
					}).then(res => {
						uni.hideLoading();
						if (res.data.code == 200) {
							that.Historylist = that.Historylist.concat(res.data.data.list);
							if(res.data.data.list.length<=0){that.Wbott=true};
							var setTime = setTimeout(function() {
								that.scroll = 1;
							}, 50)
						} else {
							that.$api.msg(res.data.data);
						}
					}, (error) => {

					})
				}
			}).exec();
		},
		onLoad() {
			var that = this;
			that.$axios('history/display', "POST", 'shop', {
				page: 1
			}).then(res => {
				if (res.data.code == 200) {
					that.Historylist = res.data.data.list
					that.scroll = 1;
				}
			}, (error) => {

			})
		},
		methods: {
			// 页面跳转
			navTo(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		color: #303133;
		font-size: 32upx;
	}

	.history-section {
		background-color: #f2f2f2;
		position: relative;
		overflow: hidden;
	}

	.history-list {
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 20upx;
		margin-bottom: 20upx;
	}

	.history-list image {
		width: 160upx;
		height: 160upx;
		margin-right: 30upx;
	}

	.list-title {
		flex: 1;
	}

	.list-title view:nth-of-type(1) {
		line-height: 45upx;
		height: 90upx;
	}

	.list-title view:nth-of-type(2) {
		color: $base-color;
		font-size: 36upx;
		padding-top: 14upx;
		text-align: right;
		padding-right: 40upx;
	}
	.bott-di{
		color: #0062CC;
		font-size: 30upx;
		line-height: 80upx;
		text-align: center;
		padding-bottom: 20upx;
	}
</style>
